<template>
    <!-- 搜索框 -->
    <CustomSearch :goSearch="goSearch"></CustomSearch>
    <!-- 动态导航栏组件 -->
    <SwipeNavBar :tabBars="tabBars" :width="15" :currentIndex="currentIndex" @changeIndex="handleChange"
        @changeTab="handleChange" :swiperList="swiperList" :scrollH="scrollH" :toolList="toolList"
        :refresherEnabled="true" @pullLoad="handleChange">
        <template v-for="(item, index) in tabBars.length" :key="index" v-slot:swiper-item="{ item, index }">
            <PostCard v-for="(item, index) in articleList" :key="item.id" :item="item"></PostCard>
        </template>
    </SwipeNavBar>
</template>
<script setup lang="ts">
import PostCard from '@/components/PostCard.vue';
import CustomSearch from '@/components/CustomSearch.vue';
import SwipeNavBar from '@/components/SwipeNavBar.vue';
import { ref, onMounted } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { API_getfindList } from '@/service/article';
import type { ArticleItem } from '@/type/article';
import { useMetaStore } from '@/store/modules/meta';
const MetaStore = useMetaStore();
const tabBars =
    [
        { id: 1, name: '推荐' },
        { id: 2, name: '最新' },
        { id: 3, name: '关注' },
    ]
const handleChange = async (index: number) => {
    currentIndex.value = index;
    let res = await API_getfindList(index);
    articleList.value = res.data;
}
const toolList = [
    {
        icon: "icon-fabu",
        func: () => {
            uni.navigateTo({ url: "/discovery_modules/publish/publish" })
        }
    }
]
const swiperList = [1, 1, 1];
//todo
const articleList = ref<ArticleItem[]>([]);
// const swiperList = ref<ArticleItem[]>([]);
let currentIndex = ref<number>(-1);
const goSearch = () => {
    uni.navigateTo({ url: '/index_modules/search/search' })
}
let scrollH = 0;
onShow(async () => {
    uni.getSystemInfo({
        success: (e) => {
            scrollH = e.windowHeight - uni.upx2px(200);
        }
    })
    currentIndex.value = MetaStore.publishReturnIndex ? 1 : 0;
    MetaStore.clearIndex();
    let res = await API_getfindList(currentIndex.value);
    articleList.value = res.data;
})
</script>
<style scoped lang="scss"></style>
